<template>
	<view>
		<view class="p-l-10 p-r-10 p-b-10">
			<view class="list bg-color m-t-5" v-for="(item,index) in newList" :key="index" v-if="newList.length>0">
				<view :class="{'fade-out':current==index}"
					style="transition: opacity 0.4s;display: flex;align-items: center;">
					<view style="flex: 1;">
						<up-text class="p-b-4" :lines="1" :text="item.title" type="primary"></up-text>
						<up-text :lines="1" :text="item.publishTimeFormat"></up-text>
					</view>
					<u-icon name="close-circle" size="22" @click="handleDel(item.id,index)"></u-icon>
				</view>
			</view>
			<view v-else style="height: 800rpx;" class="flex-center">
				<u-empty mode="message" text="暂无通知"></u-empty>
			</view>
		</view>
	</view>
</template>

<script setup>
	// import {
	// 	pageMessage,
	// 	updataMessage
	// } from "@a/public.js"

	const newList = ref([])
	const total = ref(0)
	const query = reactive({
		needCount: 1,
		pageNum: 1,
		pageSize: 20,
		isRead: 0
	})
	const current = ref(-1)

	const getMessage = async () => {
		try {
			const {
				data
			} = await pageMessage(query)
			total.value = data.total
			if (data.rows) {
				newList.value.push(...data.rows)
			}
		} catch (e) {
			console.error(e);
		}
	}

	// getMessage()

	function handleDel(id, inx) {
		current.value = inx
		updataMessage([id]).then(res => {
			setTimeout(() => {
				newList.value.splice(inx, 1)
				current.value = -1
				getMessage()
			}, 500)
		})
	}

	// 触底下拉加载
	onReachBottom(() => {
		if (query.pageNum * query.pageSize < total.value) {
			query.pageNum++
			getMessage()
		}
	})
</script>

<style lang="scss" scoped>
	.list {
		padding: 20rpx;
		border-radius: 8rpx;

		.fade-out {
			opacity: 0;
		}
	}
</style>